package com.chaosj.memory;

import cn.hutool.core.text.StrFormatter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;

/**
 * @className: MemoryEntry
 * @description:
 * @author: caoyangjie
 * @date: 2021/8/10
 **/
@Slf4j
public class MemoryEntry {
    public static void main(String[] args) {
        // 执行 命令行命令
//        args = new String[]{"help"};
//        args = new String[]{"srt", "5"};
//        args = new String[]{"poker","54"};
//        args = new String[]{"disorder", "26"};
//        args = new String[]{"gsw", "0"};
//        args = new String[]{"gsw", "1", "t", "边塞"};
//        args = new String[]{"gsw", "1", "a", "柳宗元", "1"};
//        args = new String[]{"gsw", "0", "t", "边塞", "1"};
//        args = new String[]{"gsw", "2", "t", "秋天", "1"};
//        args = new String[]{"gsw", "3", "c", "两汉", "1"};
//        args = new String[]{"gsw", "4", "t", ""};
//        args = new String[]{"searchp", "李白"};
//        args = new String[]{"rd", "e", "c2e", "10"};
//        args = new String[]{"rd", "e", "e2c", "10"};
//        args = new String[]{"rd", "e", "gre", "10"};
//        args = new String[]{"rd", "e", "tof", "10"};
//        args = new String[]{"rd", "x", "c", "10"};
//        args = new String[]{"rd", "x", "l", "10"};
//        args = new String[]{"rd", "x", "tf", "10"};
//        args = new String[]{"rd", "x", "x", "10"};
//        args = new String[]{"rd", "x", "y", "10"};
//        args = new String[]{"rd", "x", "z", "10"};
        args = new String[]{"rd","c","动物", "10"};
        boolean open = false;
        if( open ){
            StringBuffer stringBuffer = new StringBuffer();
            new CmdParserHandler().execute(args, stringBuffer);
            System.err.println(stringBuffer.toString());
        }else{
            todoList();
        }
    }

    public static void todoList(){
        String[] args = new String[]{};
        // 随机 舒尔特方格
//        args = new String[]{"srt", "5"};
        // 随机 10个 词语
//        args = new String[]{"rd", "c", "all", "-10"};
        // 随机 乱序 A—Z
//        args = new String[]{"disorder", "26"};
//         随机 乱序 1-100 数字
//        args = new String[]{"number", "20"};
        // 随机 扑克牌
//        args = new String[]{"poker","54"};
//         爬取公众号信息
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MzI3MTI2NzkxMA==&mid=2247503163&idx=1&sn=8d9b09e63cfceceffda83fd4bcd2c273&chksm=eac6ec12ddb1650463dd66e880c8c2f970d88cc679cd5d88fd9bf08dcecea2e77e869ead1d26&mpshare=1&scene=1&srcid=12258KzV0drtOmStva8OZRbI&sharer_sharetime=1640432310464&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=c71a9d4b0211931550cc02b095202070f62f439443c68aa0df8ea3335a0ce5049f7da2dda8372b1f104417e597658ba9a4ab5dc9bece00fd18944855ecc57884c0919c0548a07b8750ea9894f179ab80bbcae021ff09ec39109b8d3faf60d541ba713b7434befaec6d6ef4c47bc6d0c4e77dbf16cc4922478e3c5bf753b6f88f&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=A7TwkiCfZveBR1VcGVw2578%3D&pass_ticket=gUrtY1r9cZm5y2igQ1jKyPW5npuTFkXOdXoypfdOHKavgJpQosJEeEhbk9ZMnsty&wx_header=0"};
        // 爬取 cnblogs 信息
//        args = new String[]{"wx","https://www.cnblogs.com/zisefeizhu/p/13621797.html"};
        // 爬取 csdn 信息
//        args = new String[]{"wx","https://blog.csdn.net/linxi7/article/details/96964127"};
        // 爬取 微信 公众号
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MzkyMjMwNjEwNw==&mid=2247483664&idx=1&sn=9f62adc08b8061447738708131644cf6&chksm=c1f71244f6809b52fb3eefd282da68cb9a3de2612d657e62014406c05f54aa324a0e6eac5dfd&mpshare=1&scene=1&srcid=1228MRDdXl2t2aMh7Tphtxf0&sharer_sharetime=1640665833675&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=e5fca4930cbdd1b95826d043d2d36395a61cd99242041a7062f8316cb377768861952fe6d8e42bb86b7c3ac89a66b994f0686a8ef2723c42db00ecdce478ee41079b63cf72b3ed2b62d94793cb2642349234d1dbc14868f21101ba6d4aa7703be9c2105b7ff19a7b96e5bb07974f018af817b0203446c9c27b5ce5143653efb1&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=A1Q6xIFNBgvdayRPVsCsPcg%3D&pass_ticket=maz%2FK8vctnURoVRQSXp9%2BlxNS%2F5NFY6xuPcpx%2BX0UTYSQj96KCQypu%2Bq%2BM%2B%2BSQhk&wx_header=0"};
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MzkyMjMwNjEwNw==&mid=2247483722&idx=2&sn=e4457be5df6a8fd830a758bd64cfa91a&chksm=c1f7121ef6809b08fe4d42d300cb4de8a0c0a406326a2431dc4d1e882306ced473f0159db5c8&mpshare=1&scene=1&srcid=12286CN6XwtUzypWGytsogkl&sharer_sharetime=1640665863439&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=e5fca4930cbdd1b955ce023a082bd9b265d62c60bffda91897b960826b0a5438046777f9bfa58a229197b995c768e4783c2743658e59fe85c941814c9d3c1dc26cc04ee07f38f6e151c7a98b9d7068af05391ac120daeb549a07aeab96d1a67dd6344a5a2f51849b9c7fc408851b2438867c7e8f105839e64e340e4944ce0fc3&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=AxoRdXaR9xJCqwQPZecVzyE%3D&pass_ticket=maz%2FK8vctnURoVRQSXp9%2BlxNS%2F5NFY6xuPcpx%2BX0UTYSQj96KCQypu%2Bq%2BM%2B%2BSQhk&wx_header=0"};
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=Mzg4NDU4MDUxNA==&mid=2247487363&idx=1&sn=a6d703f7e2d2695965dcebe3ae92e5b6&chksm=cfb7464ef8c0cf58499ce831cc5a711603dec94992bd18c8b941f0a20c3003a0b3b70f3a7be3&mpshare=1&scene=1&srcid=1228Ztl5ZH8XG2ablzkTkvRI&sharer_sharetime=1640666512828&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=3cff6956ae19a5afaed024f5b4822b6c67b6fffdce7590bf7d371b009a5e9f16dc644de7b8fd1e6c4ec763a715786420a6acca4975d7738158be237f90ce8a005ffbc4da979d2f995d47671a4f8a192e37c3afd08da9f05d6a5a99b01c6e8835c1866f9f049116c43468e2c747a7991571f261ebc78e7ed6ed38bb97f368f71c&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=A2F%2B7eQmOyMwPOQAuqn1Zmc%3D&pass_ticket=maz%2FK8vctnURoVRQSXp9%2BlxNS%2F5NFY6xuPcpx%2BX0UTYSQj96KCQypu%2Bq%2BM%2B%2BSQhk&wx_header=0"};
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MzUzMTA2NTU2Ng==&mid=2247534133&idx=1&sn=a437f56ad1cb9a00ac02105e855372c5&chksm=fa4a3984cd3db09251c17785c37af1f28b8ed13845c4e65c189b803b6c0bf423d3ad20e12d6c&mpshare=1&scene=1&srcid=1228wYWfXGu8rWQA0ZeCW83i&sharer_sharetime=1640666553992&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=e5fca4930cbdd1b9fbb359d255a4699773962eb3dc51a8f0b022e66b84611fa60d547cc94cc37dbc077b0ea26a376b791a0687b90d870ba7fbf7cc9a44965962cdc7cb639fa263dcb658d2a45818505a485e0c94115d9eed8822c463bac3c901c10fe819d5097469b1e833888fa60506eddc3134f9219a602074aa3f3620a4ab&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=AzEUzLddoGDXToPq9ZiDmRg%3D&pass_ticket=maz%2FK8vctnURoVRQSXp9%2BlxNS%2F5NFY6xuPcpx%2BX0UTYSQj96KCQypu%2Bq%2BM%2B%2BSQhk&wx_header=0"};
//        args = new String[]{"wx","https://my.oschina.net/u/3874284/blog/5388059"};
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=2651960061&idx=1&sn=3747338a91e85fc33f43d9c1bb98ab10&chksm=bd2d07218a5a8e37ad2e5078736d2449a6ba1e0d75bb18d09990a5f3dcc3af2b7ff414158adb&scene=21#wechat_redirect"};
//        args = new String[]{"wx","https://www.bbsmax.com/A/LRnJWrgzqY/"};
//        args = new String[]{"wx","https://mp.weixin.qq.com/s?__biz=MjM5Nzg0MTQ3OQ==&mid=2660982611&idx=3&sn=d157cf33b7a463d34a120ba2ba674249&chksm=bdbc207b8acba96d7e53410f1db81b75b0bcd53e3c973458b7d7806c686fdffe0d7fd73ce4be&mpshare=1&scene=1&srcid=0111P01qeS2Ryzb9uPQqQ8RW&sharer_sharetime=1641859732831&sharer_shareid=3dfdf7611b96d4a1c9d35bf1da01ac4b&key=6fc66dccf4987120e884236a9d26a368f61d3f7fe27edc969e55ca5e2fbd421272c53ba014313d597388bab70f2eac33e30c649000ca19b66eadecb581d1da9fab536d017c3837cba1cc0789601728f9606979b6dda0888df707a783ae0bb39e0efe73b8c20e374550bd1628faa2d6cf349e9472216ed757bcf5cb9393d6f62c&ascene=1&uin=MjQxMDMzOTU1&devicetype=Windows+XP&version=62060841&lang=zh_TW&exportkey=A460AM12U%2F%2BiM87xxzRIWgQ%3D&pass_ticket=ik8Q9HE7DrnLnxawC7NtZewTusE1Vrnj4WC8dQV%2FqsIAeGXFjk2SHQsjXdHVYp1Q&wx_header=0"};
        // rocketmq
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119878221"};
        // sentinel
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/106005837"};
        // dubbo
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119879140"};
        // mybatis
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/97611378"};
        // netty
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119879300"};
        // JUC 工具包
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/103246606"};
        // ES 学习
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119879755"};
        // Mycat
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119879637"};
        // canal
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/article/details/119879667"};
        // Java 高并发
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_11339174.html"};
        //职场建议
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_10897336.html"};
        // 面试建议
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_10791556.html"};
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_11027528.html"};
        // 架构设计
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_10906557.html"};
        // kafka
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_9481702.html"};
        // 数据结构与算法
//        args = new String[]{"wx","https://blog.csdn.net/prestigeding/category_6431121.html"};
        // RocketMQ
//        args = new String[]{"wx","https://codingw.blog.csdn.net/category_7034876.html"};
//        args = new String[]{"wx","https://codingw.blog.csdn.net/category_7034876_2.html"};
        // 面试系列资料
//        args = new String[]{"wx","https://blog.csdn.net/ThinkWon/article/details/104397367?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164252261516780264048083%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164252261516780264048083&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_click~default-7-104397367.nonecase&utm_term=Springcloud&spm=1018.2226.3001.4450"};
//        args = new String[]{"wx","https://thinkwon.blog.csdn.net/article/details/104903925"};
//        args = new String[]{"wx","https://thinkwon.blog.csdn.net/article/details/120928777"};
        // 程序员工作经验
//        args = new String[]{"wx","https://thinkwon.blog.csdn.net/article/details/102980571"};
//        args = new String[]{"wx","https://thinkwon.blog.csdn.net/article/details/121623142"};
        // 设计模式
//        args = new String[]{"wx","https://blog.csdn.net/thinkwon/category_9382953.html"};
        // 并发编程
//        args = new String[]{"wx","https://blog.csdn.net/thinkwon/category_9393255.html"};
        // 深入JVM虚拟机
//        args = new String[]{"wx","https://blog.csdn.net/thinkwon/category_9637695.html?spm=1001.2014.3001.5482"};
        // mysql 系列
//        args = new String[]{"wx","https://binghe.blog.csdn.net/category_9755213.html"};
//        args = new String[]{"wx","https://blog.csdn.net/l1028386804?type=blog","true","3"};
//        args = new String[]{"wx","https://shanhy.blog.csdn.net/?type=blog","true","3"};
        args = new String[]{"wx","https://blog.csdn.net/lqy971966/category_9813590.html?spm=1001.2014.3001.5482"};

        // 抓取 gitbook dubbo
//        args = new String[]{"gitbook","https://www.bookstack.cn/read/apache-dubbo-3.0-zh/34d1a9093713983a.md"};
        // awk
//        args = new String[]{"gitbook","https://www.bookstack.cn/read/junmajinlong-awk_examples/ad4431d029997b90.md"};
        // effective java
//        args = new String[]{"gitbook","https://www.bookstack.cn/read/effective-java-3rd-chinese/docs-README.md"};

        StringBuffer stringBuffer = new StringBuffer();
        new CmdParserHandler().execute(args, stringBuffer);
        System.err.println(stringBuffer.toString());
//        scanner("/home/caoyangjie/logs/allMarkdown.md");

    }

    @SneakyThrows
    public static void scanner(String mdPath){
        CmdParserHandler handler = new CmdParserHandler();
        Files.readAllLines(Paths.get(mdPath)).parallelStream().forEach(line->{
            String uri = extractURI(line);
            if( filter(uri) ){
                System.out.println(StrFormatter.format("request uri => {}", uri));
                handler.execute(new String[]{"wx", uri}, new StringBuffer());
            }
        });
    }

    private static boolean filter(String uri) {
        return uri.startsWith("https://blog.csdn.net/")||
        uri.startsWith("https://www.cnblogs.com/")||
        uri.startsWith("https://mp.weixin.qq.com/");
    }

    private static String extractURI(String line){
        return line.substring(line.indexOf("(")+1,line.indexOf(")"));
    }
}
